using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SPSAndong.Entity;
using SPSAndong.Model;
using Leeder.Service;
using Leeder.Repository;

namespace SPSAndong.Service
{
    /// <summary>
    /// 
    /// </summary>
   public class DeviceExceptionMonitorService : BaseService<DeviceExceptionMonitorModel>
   {
        /// <summary>
        /// 关联实体类型
        /// </summary>
        protected override Type RefEntityType { get { return typeof(DeviceExceptionMonitorEntity); } }

        /// <summary>
        /// 根据条件获取数据总量
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public int GetPartsCountByWhere(string where)
        {
            return RF<DeviceExceptionMonitorEntity>.SqlQueryable("SELECT  * FROM SAS_DeviceExceptionMonitor " + where).Count();
        }

        public List<DeviceExceptionMonitorModel> GetModelListByPage(string where, int pageIndex, int pageSize)
        {
            if (pageIndex < 1)
                return null;
            pageIndex = (pageIndex - 1) * pageSize;
            var sql = "SELECT  * FROM SAS_DeviceExceptionMonitor " + where + " ORDER BY ExceptionDate DESC OFFSET " + pageIndex + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY";
            return RF<DeviceExceptionMonitorEntity>.SqlQueryable(sql).Select(s => new DeviceExceptionMonitorModel
            {
                ID = s.ID,
                DeviceId = s.DeviceId,
                DeviceName = s.DeviceName,
                DeviceIP = s.DeviceIP,
                DeviceType = s.DeviceType,
                ExceptionDescription = s.ExceptionDescription,
                ExceptionDate = s.ExceptionDate,
            }).ToList();
        }


    }
}